package com.ai.dbutil;

import java.sql.DriverManager;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;

/*
 * 单例模式建立数据库连接
 */
public class DBconn {
	private static Connection conn;
	
	private DBconn() {
		super();
	}
	
	public static Connection getInstance() {
	    String driver = "com.mysql.jdbc.Driver";
	    String url = "jdbc:mysql://localhost:3306/iyoga";
	    String username = "root";
	    String password = "bellusa";
	    conn = null;
	    try {
	        Class.forName(driver); //classLoader,加载对应驱动
	        conn = (Connection) DriverManager.getConnection(url, username, password);
	    } catch (ClassNotFoundException e) {
	        e.printStackTrace();
	    } catch (SQLException e) {
	        e.printStackTrace();
	    }
	    return conn;
	}
}
